package com.controller;

import com.domain.User;
import com.dto.HttpClientMapResult;
import com.service.iml.UserService;
import com.utils.JwtTokenUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private UserService userService;

    @PostMapping("/wx/nickname")
    public Map changeUserName(HttpServletRequest request, @RequestBody User user) {
        String openid = jwtTokenUtil.getIdFromToken(request);
        Integer id = userService.getUserId(openid);
        boolean res = userService.changeUserName(id, user.getUserName());
        return new HttpClientMapResult().putSuccessOrFailedMsg(res);
    }

}
